package com.admin.business.venueProjectLifeService;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 商户表
 * @create: 2022-05-26 18:46:06
 **/
@Service("VenueProjectLifeServiceService")
@Slf4j
public class VenueProjectLifeService {

    @Resource
    VenueProjectLifeServiceDao venueProjectLifeServiceDao;

    @OpenApi
    public Return deleteVenueProjectLifeService(CDO cdoRequest) {
        CDO cdoResult = new CDO();

        venueProjectLifeServiceDao.venueProjectLifeServiceDelete(cdoRequest);

        return Return.valueOf(cdoRequest);
    }

    @OpenApi
    public Return addVenueProjectLifeService(CDO cdoRequest) {
        CDO cdoResult = new CDO();
        if(cdoRequest.get("id")!=null && !cdoRequest.get("id").equals("")){
            venueProjectLifeServiceDao.venueProjectLifeServiceUpdate(cdoRequest);
        }else{
            venueProjectLifeServiceDao.venueProjectLifeServiceAdd(cdoRequest);
        }
        return Return.valueOf(cdoRequest);
    }

    @OpenApi
    public Return getVenueProjectLifeService(CDO cdoRequest) {
        CDO result = venueProjectLifeServiceDao.getVenueProjectLifeService(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("data",result);
        return Return.valueOf(result);
    }

    //服务类别
    @OpenApi
    public Return getVenueProjectLifeServiceList(CDO cdoRequest) {
        List<CDO> result = venueProjectLifeServiceDao.getVenueProjectLifeServiceList(cdoRequest);
        if (result.size()>0){
            for (CDO item:result){
                cdoRequest.set("parent_id",item.get("id"));
                List<CDO> resultChild = venueProjectLifeServiceDao.getVenueProjectLifeServiceListByP(cdoRequest);
                item.set("childList",resultChild);
            }
        }
        CDO cdoResult = new CDO();
        cdoResult.set("data",result);
        return Return.valueOf(result);
    }

    //根据服务id找到该服务id所有商户
    @OpenApi
    public Return getAllCommercialByServiceId(CDO cdoRequest){
        List<CDO> serviceList = venueProjectLifeServiceDao.selectAllCommercialByServiceId(cdoRequest);
        CDO result = new CDO();
        result.set("data",serviceList);
        return Return.valueOf(result);
    }

    //展示所有服务分类
    @OpenApi
    public Return getAllServiceCategory(CDO cdoRequest){
        List<CDO> parentList = venueProjectLifeServiceDao.selectAllParentServiceCategory(cdoRequest);
        for (CDO parent:parentList){
            List<CDO> childrenList = venueProjectLifeServiceDao.selectAllChildrenServiceCategory(parent.getString("id"));
            parent.set("childrenList",childrenList);
        }
        return Return.valueOf(parentList);
    }
}
